//
//  ActivityViewController.m
//  UI14_豆瓣完整版
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ActivityViewController.h"
#import "MyTableViewCell.h"
#import "ActivityModel.h"
#import "UIImageView+WebCache.h"
#import "ActivityViewController1.h"

@interface ActivityViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *actArr;
@property (nonatomic, retain) NSArray *tempArr;


@end

@implementation ActivityViewController

- (void)dealloc {
    [_tempArr release];
    [_tableView release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.title = @"活动";
    
    // 创建tableView
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.backgroundColor = [UIColor cyanColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
    
    // 重用池
    [_tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    // 数据解析
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    self.tempArr = [NSArray arrayWithContentsOfFile:path];
    
    self.actArr = [NSMutableArray array];
    
    for (NSDictionary *dic in _tempArr) {
        ActivityModel *model = [ActivityModel activityModel];
        [model setValuesForKeysWithDictionary:dic];
        [_actArr addObject:model];
    }
}

// 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _actArr.count;
}

// 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}

// cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    ActivityModel *model = _actArr[indexPath.row];
    
    cell.titleLabel.text = model.title;
    
    NSString *str1 = [NSString stringWithFormat:@"%@", model.begin_time];
    NSString *str2 = [str1 substringWithRange:NSMakeRange(5, 11)];
    NSString *str3 = [NSString stringWithFormat:@"%@", model.end_time];
    NSString *str4 = [str3 substringWithRange:NSMakeRange(5, 11)];
    NSString *str = [NSString stringWithFormat:@"%@|%@", str2, str4];
    cell.dateLabel.text = str;
    
    cell.addressLabel.text = model.address;
    
    cell.typeLabel.text = model.category_name;
    
    NSString *numStr1 = [NSString stringWithFormat:@"%@", model.wisher_count];
    cell.interNumLabel.text = numStr1;
    
    NSString *numStr2 = [NSString stringWithFormat:@"%@", model.participant_count];
        cell.joinNumLabel.text = numStr2;
    
    [cell.imageView3 sd_setImageWithURL:[NSURL URLWithString:model.image]];
    
    return cell;
    
}



// cell 跳转的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ActivityViewController1 *actVc = [[ActivityViewController1 alloc] init];
    [self.navigationController pushViewController:actVc animated:YES];
    
    NSDictionary *dic = _tempArr[indexPath.row];
    
    actVc.DIC = dic;
    
    
    [actVc release];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
